package 国家领导者;

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int T = Integer.parseInt(in.nextLine());
        for (int cases = 1; cases <= T; cases++) {
            int n = Integer.parseInt(in.nextLine());
            String leader = "";
            while (n-- > 0) {
                String name = in.nextLine();
                if (cmp(name, leader)) {
                    leader = name;
                }
            }
            System.out.printf("Case #%d: %s\n", cases, leader);
        }
    }

    private static boolean cmp(String name, String leader) {
        Set<Character> a = new HashSet<>();
        Set<Character> b = new HashSet<>();
        for (char c : name.toCharArray()) {
            if (c != ' ') {
                a.add(c);
            }
        }
        for (char c : leader.toCharArray()) {
            if (c != ' ') {
                b.add(c);
            }
        }
        if (a.size() != b.size()) {
            return a.size() > b.size();
        }
        return name.compareTo(leader) < 0;
    }
}
